package com.zzq.base.awesome.utils;


import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class DrawPoint {

    public static void main(String[] args) {
        String a = "151:199,150:190,147:181,146:174,144:168,142:160,141:153,140:146,138:139,137:132,135:123,134:119,132:111,131:106,131:100,129:94,128:91,127:89,126:88,126:86,126:85,125:82,124:78,124:76,124:75,124:73,124:72,124:70,124:69,124:68,124:67,124:66,124:65,124:64,124:63,124:62,124:61,124:59,124:58,124:56,124:55,124:54,127:54,132:55,140:56,149:58,156:59,162:59,164:59,165:59,168:59,172:59,175:59,179:60,181:60,186:60,188:60,190:60,191:60,192:60,193:60,194:60,195:59,195:58,196:57,196:54,196:53,197:52,197:51,197:50,197:48,197:46,197:45,197:44,196:43,195:42,194:40,193:38,193:37,192:36,191:35,190:34,190:33,188:32,187:32,184:32,182:34,181:35,179:35,178:36,176:38,175:40,173:43,172:47,171:49,169:51,168:55,168:57,167:60,167:62,167:64,166:66,166:68,166:71,166:73,166:74,166:76,166:77,166:78,166:79,166:80,166:81,166:82,166:83,166:84,166:85,167:85,169:86,172:87,177:88,185:89,189:90,194:90,196:90,197:90,199:90,201:90,205:90,209:90,211:90,212:90,213:89,214:89,215:88,216:88,216:87,217:87,217:86,218:85,218:84,217:82,216:82,215:82,212:82,210:82,208:82,207:82,206:82,204:83,203:84,202:85,201:88,199:90,198:93,196:97,194:99,194:101,193:103,192:107,190:109,190:112,189:114,188:116,188:118,188:119,188:120,188:121,188:122,188:123,188:125,189:126,189:127,190:128,191:129,193:130,195:131,197:131,201:131,205:131,209:131,215:131,216:131,215:132,214:133,213:134,211:135,209:136,208:137,207:137,206:138,205:139,205:140,207:140,210:141,216:142,225:144,230:144,236:144,241:144,244:144,246:144,247:142,248:141,249:141,250:138,250:136,252:135,253:132,253:131,255:129,256:126,257:122,259:118,260:114,262:111,263:107,264:104,265:101,265:98,265:96,265:95,265:94,265:92,265:90,265:88,263:86,263:84,263:81,261:79,261:78,261:77,261:75,261:74,261:73,261:72,261:71,262:70,263:69,265:68,267:68,268:67,270:66,271:66,274:65,277:65,281:65,286:65,295:65,298:65,306:65,309:66,312:67,314:68,316:69,317:70,318:72,319:74,319:75,319:76,319:77,319:78,320:81,320:82,320:83,320:84,320:86,320:89,319:93,318:94,317:98,316:100,315:103,314:104,313:107,312:109,310:111,309:114,308:116,306:118,305:119,305:120,304:121,303:123,303:124,302:125,302:126,302:127,301:127,301:128,300:131,300:132,300:133,300:134,300:136,300:137,300:138,300:140,301:141,302:142,304:143,306:144,307:144,309:144,311:144,315:145,319:145,323:145,327:145,332:145,338:145,340:145,346:145,350:145,353:145,358:145,361:145,364:145,368:145,371:145,375:145,379:145,383:144,387:143,392:143,396:142,398:141,401:140,405:140,408:139,415:137,417:137,423:136,427:135,432:134,434:133,435:132,437:132,440:131,443:129,445:129,448:127,451:126,453:124,456:123,459:121,462:120,464:118,466:116,467:115,469:114,470:113,471:113,472:112,472:111,472:110,472:107,472:105,472:101,472:98,471:93,470:91,468:88,466:86,464:84,460:83,454:81,446:79,440:79,430:76,427:76,422:75,420:75,416:75,411:75,407:75,403:75,401:75,400:75,398:75,397:75,396:75,394:75,393:76,390:78,387:79,385:81,383:84,381:85,380:88,378:91,377:93,375:95,374:97,373:99,373:100,373:101,371:105,371:107,371:108,370:110,370:112,370:113,370:114,370:115,370:117,370:118,370:120,370:121,371:123,371:125,370:123,368:122,364:117,361:113,358:109,355:107,355:106,354:103,354:100,354:98,354:97,354:95,354:93,354:91,355:88,355:87,355:85,356:83,358:81,359:79,362:76,365:74,368:72,371:70,373:69,377:67,380:66,383:65,385:64,389:63,392:62,396:62,401:62,408:62,415:62,422:62,428:62,436:62,441:63,448:64,455:65,461:67,467:68,472:69,479:71,485:74,491:75,498:77,509:79,516:81,523:83,528:83,534:84,539:86,543:87,547:87,553:88,559:90,564:91,569:92,573:93,577:94,581:96,584:97,589:98,592:100,596:101,603:104,608:106,613:109,620:110,627:111,633:113,639:114,645:115,651:117,657:117,666:119,676:121,687:124,700:126,712:128,722:128,735:128,749:128,760:128,769:128,779:128,785:128,789:128,796:127,800:126,805:125,810:124,813:123,815:121,816:120,817:118,817:117,817:115,817:112,817:111,817:109,817:107,817:105,817:102,816:100,815:100,813:98,811:97,808:97,805:97,801:95,795:94,787:93,778:91,771:91,763:91,758:91,755:91,754:91,753:91,749:91,744:93,738:96,730:99,724:101,720:102,716:103,713:103,710:103,705:105,700:105,692:105,685:105,676:105,667:105,662:104,657:103,655:102,654:101,653:100,653:99,653:97,653:95,653:94,653:91,653:89,653:87,654:86,655:85,658:84,662:82,665:81,670:80,676:80,684:80,695:80,704:80,714:80,721:80,725:80,728:80,731:80,736:80,741:81,747:82,754:84,761:87,763:88,769:91,774:94,778:97,781:97,788:102,793:105,799:108,805:112,812:116,818:120,823:123,829:126,833:129,838:132,841:134,846:136,851:139,856:142,862:144,866:145,872:147,876:148,881:148,889:148,897:148,907:148,917:148,927:148,938:148,949:148,961:148,972:148,978:147,985:146,988:144,992:143,996:142,1001:140,1004:137,1010:134,1014:131,1016:130,1022:127,1025:126,1027:124,1029:122,1030:121,1031:119,1032:117,1032:115,1032:114,1033:112,1034:110,1034:106,1034:102,1034:99,1034:98,1033:97,1032:97,1029:96,1025:95,1020:95,1014:95,1010:95,1009:95,1008:95,1003:95,997:96,991:97,985:98,980:100,978:100,977:100,973:102,970:103,963:106,961:107,956:109,953:110,950:113,947:115,942:118,939:120,935:123,932:125,930:126,928:127,926:128,925:128,924:129,921:129,918:129,912:128,905:127,893:125,877:120,871:118,869:116,867:115,866:113,866:111,866:110,866:106,866:103,866:99,866:97,866:94,867:91,868:90,870:88,871:86,873:84,875:83,878:83,885:80,892:79,899:79,906:79,913:79,922:79,931:80,940:82,946:84,951:85,957:86,964:87,972:89,981:90,990:92,997:94,1002:94,1009:96,1015:98,1022:98,1028:98,1035:99,1043:100,1054:101,1062:101,1065:101,1077:101,1085:101,1092:101,1101:101,1107:101,1115:101,1123:101,1131:101,1141:100,1147:99,1154:98,1161:96,1167:95,1174:95,1180:94,1189:94,1200:94,1212:94,1225:94,1247:94,1260:94,1273:94,1281:94,1288:94,1292:94,1296:94,1297:94,1298:94,1300:94,1303:94,1308:94,1314:96,1320:97,1327:98,1336:100,1344:102,1359:105,1366:106,1373:108,1378:109,1380:109,1387:111,1390:111,1393:111,1395:112,1396:112,1396:113,1396:114,1395:115,1394:116,1391:118,1389:119,1387:121,1382:124,1378:126,1372:130,1366:134,1359:138,1355:141,1354:141,1353:141,1352:142,1352:143,1350:143,1344:145,1335:149,1319:152,1314:153,1295:157,1284:159,1275:162,1270:163,1268:163,1267:163,1266:163,1265:163,1261:164,1252:166,1243:168,1232:170,1221:172,1211:175,1205:177,1203:177,1202:177,1201:177,1200:177,1198:177,1195:177,1191:177,1188:177,1184:177,1181:177,1177:177,1173:177,1171:177,1166:177,1161:177,1155:177,1150:177,1144:177,1140:177,1138:177,1137:177,1136:177,1134:176,1131:174,1129:171,1126:165,1124:161,1122:157,1121:153,1121:152,1121:150,1121:149,1121:147,1121:145,1121:143,1121:140,1121:138,1121:137,1121:136,1121:135,1122:136,1124:137,1127:139,1133:141,1138:142,1144:143,1148:144,1152:145,1156:145,1159:145,1161:145,1162:145,1165:145,1167:145,1171:145,1174:145,1178:147,1179:147,1181:148,1182:149,1184:150,1188:152,1191:154,1193:154,1199:157,1202:157,1205:157,1210:157,1215:156,1217:155,1220:153,1221:151,1223:150,1224:149,1224:148,1224:147,1224:146,1224:144,1224:142,1224:139,1224:138,1224:135,1223:133,1222:131,1221:130,1219:130,1218:129,1216:129,1213:129,1209:129,1203:129,1196:129,1189:129,1184:129,1178:129,1176:129,1173:129,1171:129,1166:129,1160:129,1153:129,1146:129,1140:129,1134:129,1133:129,1130:129,1128:129,1123:130,1119:130,1116:131,1112:131,1109:131,1104:131,1101:131,1098:131,1094:131,1091:131,1085:131,1081:131,1075:131,1071:132,1070:133,1068:134,1066:135,1063:137,1061:139,1059:140,1057:142,1055:145,1053:148,1050:151,1048:155,1046:159,1043:162,1041:165,1040:167,1039:168,1038:169,1037:169,1035:169,1034:170,1033:171,1030:172,1023:174,1018:176,1012:176,1008:178,1003:179,997:179,992:179,987:179,981:179,973:179,965:179,957:179,948:179,940:179,932:179,924:179,915:179,908:179,899:179,894:179,892:179,888:179,882:179,879:179,875:179,872:179,869:179,864:179,860:179,857:179,852:179,849:179,845:179,840:179,836:179,831:179,827:179,821:179,819:179,813:179,807:179,800:179,795:179,789:179,783:179,778:179,773:179,768:179,764:179,759:179,755:179,749:179,743:179,737:179,731:179,724:179,718:179,712:179,708:179,703:179,700:179,696:179,691:179,686:179,680:179,676:179,672:179,667:179,662:179,658:179,653:179,647:179,642:181,638:181,634:182,631:182,625:182,621:183,614:185,611:185,607:185,601:185,598:186,594:186,591:187,589:187,587:188,585:188,582:188,578:188,576:188,573:189,571:189,569:189,564:189,560:189,557:189,552:189,549:189,545:189,540:189,536:189,533:188,530:187,527:186,525:185,524:185,523:184,522:183,521:182,520:181,518:181,517:180,516:179,514:178,512:177,511:176,510:175,508:173,507:172,506:172,505:170,504:169,503:168,502:167,501:166,501:165,501:164,499:163,498:168,494:190";
        String[] aA = a.split(",");
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < aA.length; i++) {
            String[] t = aA[i].split(":");
            list.add(new int[]{Integer.parseInt(t[0]), Integer.parseInt(t[1])});
        }
        new DrawPoint().transformGray_R(1920, 200, "c://data/avatar/"
                + System.currentTimeMillis() + ".png", list);
    }


    public void transformGray_R(int width, int height, String imagePath, List<int[]> list) {
        System.out.println("黑色：" + converRgbToArgb(0, 0, 0));
        System.out.println("白色：" + converRgbToArgb(255, 255, 255));
        System.out.println("黑色：" + Arrays.toString(converArgbToRgb(-16777216)));

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int[] ints : list) {
            image.setRGB(ints[0], ints[1], converRgbToArgb(255, 255, 255));
        }
        try {
            ImageIO.write(image, "jpg", new File(imagePath));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    int converRgbToArgb(int r, int g, int b) {
        return ((0xFF << 24) | (r << 16) | (g << 8) | b);
    }

    // int转rgb
    int[] converArgbToRgb(int argb){
        int[] rgb = new int[3];
        rgb[0] = (argb & 0xff0000) >> 16;
        rgb[1] = (argb & 0xff00) >> 8;
        rgb[2] = (argb & 0xff);
        return rgb;
    }
}
